﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Srvtools;
using System.Data;

public partial class ServicesSheet_SCGY : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["id"] != null)
            {
                InitializeComponent();

                FLWebNavigator1.Visible = true;
                Master.DataSource = WMaster;
                WMaster.SetWhere("Id=" + Request["Id"].ToString());
                
                string FlowFlag = Request["FlowFlag"].ToString();
                string EmployeeId = Request["EmpId"].ToString();
                if (FlowFlag == "" && Convert.ToInt32("0" + EmployeeId) == Convert.ToInt32(Srvtools.CliUtils.fLoginUser))
                {
                }
                else
                {
                    object o = FLWebNavigator1.NavControls["Comment"];
                    // FLWebNavigator1.NavControls.Clear();
                    FLWebNavigator1.NavControls.Add(o);
                }


                DataSet ds = WMaster.Execute("SELECT SYS_TODOLIST.LISTID FROM SYS_TODOLIST WHERE  SYS_TODOLIST.FORM_TABLE='Services_SCGY'" +
                    " and SYS_TODOLIST.FORM_KEYS='Id' and  SYS_TODOLIST.FORM_PRESENTATION='Id=" + Request["Id"].ToString() + "'");
                if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    ImageButton imb = new ImageButton();
                    imb.ImageUrl = "../image/uipics/Comment_C.gif";
                    imb.ID = "i";
                    imb.Attributes.Add("onclick", "window.open('../InnerPages/FlowComment.aspx?LISTID=" + ds.Tables[0].Rows[0][0].ToString()
                        + "&ATTACHMENTS=', '', 'resizable=yes,scrollbars=yes,width=645,height=400,top=100,left=200');return false");
                    FLWebNavigator1.Controls.Add(imb);
                }
            }
            else
            {
                InitializeComponent();
                Master.DataSource = WMaster;
            }
                      


            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "~/Help/ServicesSheet/私车公用申请.htm";
            master.PageName = "私车公用出车单";
            master.PicUrl = "";
            master.IntiBar();

        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServicesSheet_SCGY));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "ServiceSheet.Services_SCGY";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }
    protected void wfvMaster_DataBound(object sender, EventArgs e)
    {
        if (this.wfvMaster.CurrentMode == FormViewMode.ReadOnly)
        {
            CheckBox cbox = (CheckBox)this.wfvMaster.FindControl("ClientCheckBox");
            if (cbox != null)
                cbox.Attributes.Add("onclick", "return false");
        }
    }

    protected string GetEmpId()
    {
        String str = Srvtools.CliUtils.GetValue("_UserCode")[1].ToString();
        str = int.Parse(str).ToString();
        return str;
    }
    protected void wfvMaster_ItemInserting(object sender, FormViewInsertEventArgs e)
    {

        TextBox tbDate = (TextBox)this.wfvMaster.FindControl("ZLTextBox1");
        Srvtools.WebRefVal wfvEmp = (Srvtools.WebRefVal)this.wfvMaster.FindControl("WebRefVal1");
        int year = Convert.ToDateTime(tbDate.Text).Year;
        string empId = wfvEmp.BindingValue;

        object[] objParam = new object[2];
        objParam[0] = year;
        objParam[1] = empId;
        object[] myRet = Srvtools.CliUtils.CallMethod("ServiceSheet", "GetSubsidyId", objParam);
        if (myRet != null && (int)myRet[0] == 0)
        {
            if (Convert.ToInt32(myRet[1]) == 0)
            {

            }
            else
            {
                e.Values["SubsidyId"] = myRet[1];
            }
        }
    }

    protected void wfvMaster_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        BaseText.ZLTextBox tbDate = (BaseText.ZLTextBox)this.wfvMaster.FindControl("ZLTextBox1");
        Srvtools.WebRefVal wfvEmp = (Srvtools.WebRefVal)this.wfvMaster.FindControl("WebRefVal1");
        int year = tbDate.GetDateTime.Year;
        string empId = wfvEmp.BindingValue;

        object[] objParam = new object[2];
        objParam[0] = year;
        objParam[1] = empId;
        object[] myRet = Srvtools.CliUtils.CallMethod("ServiceSheet", "GetSubsidyId", objParam);
        if (myRet != null && (int)myRet[0] == 0)
        {
            if (Convert.ToInt32(myRet[1]) == 0)
            {

            }
            else
            {
                e.NewValues["SubsidyId"] = myRet[1];
            }
        }
    }
    protected void FLWebNavigator1_Command(object sender, CommandEventArgs e)
    {
         if (e.CommandName == "cmdApply")
        {
            if (IsPostBack == true)
            {
                if (Request["id"] != null)
                {
                    //Master.Reload();
                    Master.SetWhere("Id=" + Request["Id"].ToString());
                }
                
            }

        }
    }
}
